<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="认证类型" prop="checkType">
        <el-select v-model="queryParams.checkType" placeholder="认证类型" clearable>
          <el-option v-for="dict in dict.type.check_type" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="审核状态" clearable>
          <el-option v-for="dict in dict.type.app_check_status" :key="dict.value" :label="dict.label"
                     :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="爱洞ID" prop="platformId">
        <el-input v-model="queryParams.platformId" placeholder="请输入爱洞ID" clearable
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userCheckList">
      <el-table-column label="爱动ID" align="center" prop="platformId">
        <template slot-scope="scope">
          <a v-if="scope.row.userSex === 1" style="color: #FF6EC7" @click="toUserInfo(scope.row.platformId)">{{ scope.row.platformId }}
          </a>
          <a v-else style="color: #7099F9" @click="toUserInfo(scope.row.platformId)">{{ scope.row.platformId }}
          </a>
        </template>
      </el-table-column>
      <el-table-column label="用户性别" align="center" prop="userSex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.userSex"/>
        </template>
      </el-table-column>
      <el-table-column label="真人认证" align="center" prop="checkType">
        <template slot-scope="scope">
            <span>
            <ImagePreview :src="scope.row.videoAuthUrl" width="100px" height="100px"></ImagePreview>
          </span>
        </template>
      </el-table-column>

      <el-table-column label="审核类型" align="center" prop="checkType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.check_type" :value="scope.row.checkType"/>
        </template>
      </el-table-column>


      <el-table-column label="审核资源" align="center" prop="checkRes">

        <template slot-scope="scope">

          <span v-if="scope.row.checkType===7">
            {{ scope.row.checkRes.nickName }}
          </span>

          <span v-if="scope.row.checkType===6">
            <VoicePreview :src="scope.row.checkRes.voiceUrl"></VoicePreview>
          </span>

          <span v-if="scope.row.checkType===5">
            <ImagePreview :src="scope.row.checkRes.coverUrl" width="100px" height="100px"></ImagePreview>
          </span>


          <span v-if="scope.row.checkType===4" @click="startVideo(scope.row.checkRes.videoIntro)">
            <video :style="{
              width: `100px`,
              height: `100px`,
              backgroundColor: 'black',
              borderRadius: '5px',
              border: '1px solid'
            }" :src="prefixUrl + scope.row.checkRes.videoIntro">
              <source :src="prefixUrl + scope.row.checkRes.videoIntro" type="video/mp4">
            </video>
<!--            <VideoPreview :src="scope.row.checkRes.videoIntro">-->
<!--            </VideoPreview>-->
          </span>


          <span v-if="scope.row.checkType===3">
            <ImagePreview :src="scope.row.checkRes.headUrl" width="100px" height="100px"></ImagePreview>

          </span>


          <span v-if="scope.row.checkType===2"
                style="display: flex; flex-direction: column; justify-content: center;align-items: center;">
            <span>姓名:{{ scope.row.checkRes.realName }}</span>
            <span>身份证:{{ scope.row.checkRes.cardNum }}</span>
          </span>


          <span v-if="scope.row.checkType===1">
            <ImagePreview :src="scope.row.checkRes.resUrl" width="100px" height="100px">
            </ImagePreview>

          </span>

          <!--    <span v-else>
            {{scope.row.checkRes}}
          </span> -->

        </template>


      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_check_status" :value="scope.row.status"/>
        </template>
      </el-table-column>

      <el-table-column label="审核人" align="center" prop="updateBy"></el-table-column>
      <el-table-column label="审核时间" align="center" prop="updateTime"></el-table-column>
      <el-table-column label="操作备注" align="center" prop="remark"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button :disabled="scope.row.status==1 || scope.row.checkType!=1" size="mini" type="text" icon="el-icon-check"
                     @click="handleFace(scope.row)" v-hasPermi="['system:userCheck:edit']">颜值设置
          </el-button>
          <el-button :disabled="scope.row.status==1" size="mini" type="text" icon="el-icon-check"
                     @click="handleDelete(scope.row)" v-hasPermi="['system:userCheck:remove']">删除记录
          </el-button>
          <el-button :disabled="scope.row.status!=1" size="mini" type="text" icon="el-icon-check"
                     @click="handlePass(scope.row)" v-hasPermi="['system:userCheck:pass']">审核通过
          </el-button>
          <el-button :disabled="scope.row.status!=1" size="mini" type="text" icon="el-icon-close"
                     @click="handleRefuse(scope.row)" v-hasPermi="['system:userCheck:refuse']">审核拒绝
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>


    <!-- 颜值设置 -->
    <el-dialog title="颜值设置" :visible.sync="openFace" width="500px" append-to-body>
      <el-form ref="form" :model="bo" :rules="rules" label-width="80px">
        <el-form-item prop="faceScore">
          <el-radio-group v-model="bo.faceScore">
            <el-radio label="0">低颜值</el-radio>
            <el-radio label="1">普通颜值</el-radio>
            <el-radio label="2">高颜值</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="toFace">确 定</el-button>
        <el-button @click="openFace=false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 通过审核 -->
    <el-dialog title="通过审核" :visible.sync="openPass" width="500px" append-to-body>
      <el-form ref="form" :model="bo" :rules="rules" label-width="80px">
        <el-form-item label="操作备注" prop="reason">
          <el-input v-model="bo.reason" placeholder="请输入操作备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="toPass">确 定</el-button>
        <el-button @click="openPass=false">取 消</el-button>
      </div>
    </el-dialog>


    <!--拒绝审核 -->
    <el-dialog title="拒绝审核" :visible.sync="openRefuse" width="500px" append-to-body>
      <el-form ref="form" :model="bo" :rules="rules" label-width="80px">
        <el-form-item label="操作备注" prop="reason">
          <el-input v-model="bo.reason" placeholder="请输入操作备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="toRefuse">确 定</el-button>
        <el-button @click="openRefuse=false">取 消</el-button>
      </div>
    </el-dialog>

    <!--视频播放 -->
    <el-dialog title="视频播放" :visible.sync="openVideo" width="400px" :before-close="closeVideo" top="15vh">
      <div>
        <video id="video" :style="{
        width: '100%',
        height: '100%'
      }" autoplay="autoplay">
          <source :src="videoUrl" type="video/mp4">
        </video>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {delUserCheck, faceScore, listUserCheck, pass, refuse} from "@/api/service/userCheck/userCheck";

export default {
  name: "UserCheck",
  dicts: ['check_type', 'app_check_status', 'sys_user_sex'],
  data() {
    return {
      openVideo: false,
      videoUrl:undefined,
      bo: {},
      openRefuse: false,
      openPass: false,
      openFace: false,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息审核表格数据
      userCheckList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        checkType: undefined,
        platformId: undefined,
        status: '1',
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      prefixUrl: this.$resVideoBaseUrl
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除审核记录编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delUserCheck(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 查询用户信息审核列表 */
    getList() {
      this.loading = true;
      listUserCheck(this.queryParams).then(response => {
        this.userCheckList = response.rows;
        this.userCheckList.forEach(item => {
          item.checkRes = JSON.parse(item.checkRes)
        })

        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        userId: undefined,
        checkType: undefined,
        status: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        checkRes: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 审核通过 */
    handlePass(row) {
      this.bo.id = row.id
      this.openPass = true;
    },

    /** 审核通过 */
    handleFace(row) {
      this.bo.id = row.userId
      this.openFace = true;
    },

    /** 删除按钮操作 */
    handleRefuse(row) {
      this.bo.id = row.id
      this.openRefuse = true;
    },
    toPass() {
      pass(this.bo).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.openPass = false;
        this.getList();
      }).finally(() => {
        this.buttonLoading = false;
      });
    },
    toRefuse() {
      refuse(this.bo).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.openRefuse = false;
        this.getList();
      }).finally(() => {
        this.buttonLoading = false;
      });
    },
    toFace() {
      faceScore(this.bo).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.openFace = false;
        this.getList();
      }).finally(() => {
        this.buttonLoading = false;
      });
    },
    /**
     * 点击用户爱动id跳转到用户页面
     * @param platformId
     */
    toUserInfo(platformId) {
      this.$router.push({path: "/user/appUser", query: {id: platformId}});
    },
    closeVideo(){
      this.openVideo = false;
      this.videoUrl = undefined;
      const video = document.getElementById('video');
      video.pause();
      video.currentTime = 0;
    },
    startVideo(url){
      this.videoUrl = this.prefixUrl + url;
      this.openVideo = true;
      const video = document.getElementById('video');
      video.load();
      video.play();
    }
  }
};
</script>
